home *** CD-ROM | disk | FTP | other *** search
/ Aminet 7 / Aminet 7 - August 1995.iso / Aminet / docs / misc / ConcNews.lha / news / amiga.programming / comp.sys.amiga.programmer_9002_000048.msg < prev    next >
Encoding:
Internet Message Format  |  1994-11-27  |  2.5 KB

  1. Path: dd.chalmers.se!news.chalmers.se!sunic!ugle.unit.no!trane.uninett.no!eunet.no!EU.net!howland.reston.ans.net!europa.eng.gtefsd.com!darwin.sura.net!osceola.cs.ucf.edu!longwood.cs.ucf.edu!not-for-mail
  2. From: kruse@longwood.cs.ucf.edu (Holger Kruse)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: Removing Task started with CreateNewProc
  5. Date: 11 Apr 1994 17:45:44 -0400
  6. Organization: University of Central Florida
  7. Lines: 52
  8. Message-ID: <2ocge8$mpo@longwood.cs.ucf.edu>
  9. References: <rknopCo3z57.Azo@netcom.com>
  10. NNTP-Posting-Host: longwood.cs.ucf.edu
  11.  
  12. rknop@netcom.com (Robert Knop) writes:
  13.  
  14. >I have a parent process that creates a child process with the dos.library
  15. >CreateNewProc, using the NP_Entry tag (as opposed to the NP_SegList tag).
  16. >When I want to finish the task, the parent process sends a message to the
  17. >child process, telling it to clean up.  The child process cleans up
  18. >_everything_ it has allocated, and then does:
  19.  
  20. >ReplyMsg(msg);
  21. >Wait(0L);
  22.  
  23. >When the parent process gets the reply to the "clean up" message, it takes
  24. >that to mean that the child process is cleaned up and ready to be killed, so
  25. >it calls RemTask(childprocess).
  26.  
  27. I see two problems with your method:
  28.  - Exec might preempt your child task during ReplyMsg(msg), so when
  29.    you RemTask() it, it is still within the ReplyMsg(), and has not
  30.    yet reached the Wait(). This might not be fatal though.
  31.  - Here is the real problem: RemTask() should not be used for DOS
  32.    processes, because DOS processes have a DOS environment, that
  33.    needs cleanup, too. This is done automatically for you if you
  34.    just "fall through", i.e. execute a RTS at the end of your
  35.    subroutine. Then the program executes the necessary DOS-related
  36.    cleanup and removes the task from exec's list.
  37.  
  38. The code I use in one of my programs looks like this:
  39.  
  40. main process:
  41.  
  42.   CreateNewProc(....)
  43.   -- some synchronization for startup --
  44.   [...task is running...]
  45.   Wait(SIGBREAKF_CTRL_F); /* I guess you could use messages instead of
  46.                           signals here, too) */
  47.   /* nothing else to do here. Child task has finished */
  48.  
  49. child process:
  50.  
  51.   -- some synchronization for startup --
  52.   [... task is running ...]
  53.   Forbid(); /* necessary to make sure that the task is really removed
  54.                before the main program _assumes_ that it is gone. */
  55.   Signal(parent,SIGBREAKF_CTRL_F);
  56.   /* fall through to the end of the C function */
  57.  
  58. If you use messages instead of signals the synchronization gets quite
  59. similar to the one used by Workbench.
  60.  
  61. Holger Kruse
  62. kruse@cs.ucf.edu
  63.